package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.OwnerSelectNewBean;
import com.renwei.yunlong.bean.SponsorBean;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

import java.util.List;

/**
 * 服务商  工单  服务对象
 *
 * Created by Administrator on 2017/9/13.
 */

public class ServiceSelectNewAdapter extends RecyclerView.Adapter<ServiceSelectNewAdapter.ServiceSelectNewViewHolder>{

    private Context context;
    private LayoutInflater inflater;
    List<OwnerSelectNewBean.Rows> mList;

    private OnItemClickListener mOnItemClickListener;

    public ServiceSelectNewAdapter(Context context, List<OwnerSelectNewBean.Rows> mList){
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public ServiceSelectNewViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_select_new,null);
        AutoUtils.auto(view);
        return new ServiceSelectNewViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ServiceSelectNewViewHolder holder, int position) {
        final OwnerSelectNewBean.Rows rows = mList.get(position);
        holder.tvName.setText(rows.getHardName());
        holder.tvModel.setText(rows.getHardSerial()+"/");
        holder.tvClassification.setText(rows.getHardwareTypeName());
        //状态0-正常，1-待检测，2-维修，3-借出，4报废，5-闲置
        if ("0".equals(rows.getCurStatus())){
            holder.tvStatus.setText("正常");
            holder.tvStatus.setTextColor(Color.parseColor("#3BBE7C"));
        }else if ("1".equals(rows.getCurStatus())){
            holder.tvStatus.setText("待检测");
            holder.tvStatus.setTextColor(Color.parseColor("#E64545"));
        }else if ("2".equals(rows.getCurStatus())){
            holder.tvStatus.setText("维修");
            holder.tvStatus.setTextColor(Color.parseColor("#F5A52C"));
        }else if ("3".equals(rows.getCurStatus())){
            holder.tvStatus.setText("借出");
            holder.tvStatus.setTextColor(Color.parseColor("#F3BA73"));
        }else if ("4".equals(rows.getCurStatus())){
            holder.tvStatus.setText("4报废");
            holder.tvStatus.setTextColor(Color.parseColor("#E64545"));
        }else if ("5".equals(rows.getCurStatus())){
            holder.tvStatus.setText("闲置");
            holder.tvStatus.setTextColor(Color.parseColor("#F8BE77"));
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = holder.getLayoutPosition();
                mOnItemClickListener.onItemClick(holder.itemView,pos,rows.getHardName(),rows.getHardwareId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null?0:mList.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener = onItemClickListener;
    }
    public interface OnItemClickListener{
        void onItemClick(View view, int position, String name,String hardwareId);
    }


    static class ServiceSelectNewViewHolder extends RecyclerView.ViewHolder{

        private View itemView;
        private TextView tvName;//名称
        private TextView tvModel;//部门
        private TextView tvClassification;//分类
        private TextView tvStatus;//状态

        public ServiceSelectNewViewHolder(View view) {
            super(view);
            itemView = view;
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvModel = (TextView) itemView.findViewById(R.id.tv_model);
            tvClassification = (TextView) itemView.findViewById(R.id.tv_classification);
            tvStatus = (TextView) itemView.findViewById(R.id.tv_status);
        }
    }
}
